from django.db import models

# Create your models here.
from BaseModels import BaseModel
from DjangoUeditor.models import UEditorField


class NewsCategory(BaseModel.CreateAndUpdateAtBaseModel):
    name = models.CharField('新闻类别', max_length=32, db_index=True, unique=True)
    p_category = models.ForeignKey('self', verbose_name='父级新闻类别', on_delete=models.CASCADE, null=True, blank=True,
                                   related_name='parent_news_category')

    def __str__(self):
        return self.name

    class Meta:
        db_table = 'news_category'
        verbose_name = '新闻类别'
        verbose_name_plural = '新闻类别管理'
        permissions = {
        }


class News(BaseModel.CreateAndUpdateAtBaseModel):
    title = UEditorField(max_length=256, verbose_name='标题', toolbars='normal', width=1000, height=300, null=True,
                         blank=True)
    sub_title = UEditorField(max_length=256, verbose_name='副标题', toolbars='normal', width=1000, height=300,
                             null=True, blank=True)
    description = UEditorField(max_length=256, verbose_name='描述', toolbars='normal', width=1000, height=300,
                               null=True, blank=True)
    detail = UEditorField(verbose_name=u"内容",
                          imagePath="ueditor/news/images/%(basename)s_%(rnd)s_%(datetime)s.%(extname)s",
                          width=1000, height=300,
                          filePath="ueditor/news/files/%(basename)s_%(rnd)s_%(datetime)s.%(extname)s", default='',
                          toolbars='full', null=True, blank=True)

    def __str__(self):
        return self.title

    class Meta:
        db_table = 'news'
        verbose_name = '新闻'
        verbose_name_plural = '新闻管理'
        permissions = {
        }
